﻿using AutoDeployForSims.From18To10Cfg.Model;
using AutoDeployForSims.From18To10Cfg.Utility;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows;

namespace AutoDeployForSims.From18To10Cfg
{
    public class GetInit18Config
    {
        //转换顺序表
        private string[] childTypes18 = { "全体模拟量", "记录曲线" };
        //转换顺序表
        private List<string> analogExtendKey = new List<string>()
        {
            "扩展列序号",
            "数据类型",
            "名称",
            "模拟量类型",
            "模拟量序号",
            "analog大排队序号",
            "预警上下限",
            "倍率开关",
            "倍率系数",
            "报警延迟时间",
            "报警恢复时间",
            "报警明文设置",
            "波动判断标志",
            "校对调整值",
            "波动幅度",
            "波动频率",
            "分析时长",
            "一档突变百分比",
            "二档突变百分比",
            "三档突变百分比",
            "采集频率",
            "改方上下限",
            "改方开关量",
            "雨天上下限",
            "咽喉码",
            "区段自排队序号",
            "晴雨天标记",
            "状态标记",
            "通配开关量",
            "稳态前驱查找时间",
            "稳态后驱查找时间",
            "负值上下限",
            "灯位信息",
            "红灯",
            "绿灯",
            "黄灯",
            "白灯",
            "蓝灯",
            "绿灯2(双绿)",
            "黄灯2(双黄)",
            "USU(黄闪黄)",
            "红闪/蓝闪(调)",
            "BS(白闪)",
            "LS(绿闪)",
            "US(黄闪)",
            "绿黄",
            "红白",
            "灭灯",
            //开关量key
            "设备描述",
            "报警级别",
            "预留字段",
            "报警明文设置",
            //道岔曲线Key
            "定位表示开关量",
            "反位表示开关量",
            "曲线类型",
            "曲线过滤点数",
            "道岔前红开关量",
            "道岔前白开关量",
            "预留开关量",
            "1DQJ开关量",
            "预留开关量1",
            "预留开关量2",
            "预留开关量3",
            "预留开关量4",
            "预留开关量5",
            "预留开关量6",
            "预留开关量7",
            "预留开关量8",
            "转辙机动作超限次数",
            "定到反动作超限时间",
            "定到反动作超限值",
            "调整曲线错序",
            "反到定动作超限时间",
            "反到定动作超限值",
            //记录曲线Key
        };
        //analog子项对应关系表
        private Dictionary<string, string> analogChild18Map = new Dictionary<string, string>();
        public Dictionary<string, string> AnalogChild18Map
        {
            get { return analogChild18Map; }
            set { analogChild18Map = value; }
        }
        //普通模拟量元素map
        private Dictionary<int, AnalogEnt18> analog18EntMap = new Dictionary<int, AnalogEnt18>();
        public Dictionary<int, AnalogEnt18> Analog18EntMap
        {
            get { return analog18EntMap; }
            set { analog18EntMap = value; }
        }
        //绝缘模拟量元素map
        private Dictionary<int, AnalogEnt18> analogJY18EntMap = new Dictionary<int, AnalogEnt18>();
        public Dictionary<int, AnalogEnt18> AnalogJY18EntMap
        {
            get { return analogJY18EntMap; }
            set { analogJY18EntMap = value; }
        }
        //漏流模拟量元素map
        private Dictionary<int, AnalogEnt18> analogLL18EntMap = new Dictionary<int, AnalogEnt18>();
        public Dictionary<int, AnalogEnt18> AnalogLL18EntMap
        {
            get { return analogLL18EntMap; }
            set { analogLL18EntMap = value; }
        }
        //道岔曲线模拟量元素map
        private Dictionary<int, AnalogEnt18> curveDC18EntMap = new Dictionary<int, AnalogEnt18>();
        public Dictionary<int, AnalogEnt18> CurveDC18EntMap
        {
            get { return curveDC18EntMap; }
            set { curveDC18EntMap = value; }
        }
        //曲线模拟量元素map
        private Dictionary<int, AnalogEnt18> curveOther18EntMap = new Dictionary<int, AnalogEnt18>();
        public Dictionary<int, AnalogEnt18> CurveOther18EntMap
        {
            get { return curveOther18EntMap; }
            set { curveOther18EntMap = value; }
        }
        //模拟量扩展元素map
        private Dictionary<int, AnalogExtend18> analogExtend18EntMap = new Dictionary<int, AnalogExtend18>();
        public Dictionary<int, AnalogExtend18> AnalogExtend18EntMap
        {
            get { return analogExtend18EntMap; }
            set { analogExtend18EntMap = value; }
        }
        //曲线扩展元素map
        private Dictionary<int, AnalogExtend18> curveExtend18EntMap = new Dictionary<int, AnalogExtend18>();
        public Dictionary<int, AnalogExtend18> CurveExtend18EntMap
        {
            get { return curveExtend18EntMap; }
            set { curveExtend18EntMap = value; }
        }
        //开关量扩展元素map
        private Dictionary<int, AnalogExtend18> digitExtend18EntMap = new Dictionary<int, AnalogExtend18>();
        public Dictionary<int, AnalogExtend18> DigitExtend18EntMap
        {
            get { return digitExtend18EntMap; }
            set { digitExtend18EntMap = value; }
        }

        public bool readAnalog18(string file18Path, string telCode)
        {
            bool isRight = false;
            string strChildNum = "";
            //analog存在
            string fileAnalogPath = file18Path + telCode + "/analog.ini";
            if (!File.Exists(fileAnalogPath))
            {
                return isRight;
            }
            try
            {
                string childNumStr = ReadIni.GetProfileString(fileAnalogPath, "模拟量项目", "子项数目", "-1");
                if (childNumStr == "" || childNumStr == "-1")
                {
                    return isRight;
                }
                //检查是否为数字
                if (Regex.IsMatch(childNumStr, "[0-9]+"))
                {
                    int chirdNum = int.Parse(childNumStr);
                    int startID = 1;
                    int changeAnalogNum = 0;
                    //获取analog中所有子项的子项类型与序号对应关系
                    for (int i = 1; i <= chirdNum; i++)
                    {
                        string childName = "子项" + i;
                        string childTypeName = ReadIni.GetProfileString(fileAnalogPath, childName, "名称", "");
                        AnalogChild18Map.Add(childTypeName, childName);
                    }
                    foreach (string strChildType18 in childTypes18)
                    {
                        //System.out.println(strChildType18);
                        //根据类型码读取字段
                        if (AnalogChild18Map.ContainsKey(strChildType18))
                        {
                            strChildNum = AnalogChild18Map[strChildType18];
                        }
                        else
                        {
                            continue;
                        }
                        if (strChildType18 == "全体模拟量")
                        {
                            changeAnalogNum = ReadAnalog18Ent(fileAnalogPath, strChildNum);
                            if (changeAnalogNum <= 0)
                            {
                                //出错
                                continue;
                            }
                            else
                            {
                                Debug.WriteLine("获取到模拟量:" + changeAnalogNum);
                            }
                        }
                        else if (strChildType18 == "记录曲线")
                        {
                            changeAnalogNum = ReadCurve18Ent(fileAnalogPath, strChildNum);
                            if (changeAnalogNum <= 0)
                            {
                                //出错
                                continue;
                            }
                            else
                            {
                                Debug.WriteLine("获取到记录曲线:" + changeAnalogNum);
                            }
                        }
                        else
                        {
                            Debug.WriteLine("ERROR：未知子项名称！");
                        }
                    }

                }
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message);
            }

            return isRight;
        }

        public bool readAnalogExtend18(string file18Path, string telCode)
        {
            bool isRight = false;
            //analog存在
            string fileAnalogExtendPath = file18Path + telCode + "/analogExtend.ini";
            if (!File.Exists(fileAnalogExtendPath))
            {
                return isRight;
            }
            try
            {
                string childNumStr = ReadIni.GetProfileString(fileAnalogExtendPath, "模拟量扩展列信息", "总路数", "-1");
                if (childNumStr == "" || childNumStr == "-1")
                {
                    return isRight;
                }
                //检查是否为数字
                if (Regex.IsMatch(childNumStr, "[0-9]+"))
                {
                    int childAnalogExtendNum = int.Parse(childNumStr);
                    int changeAnalogNum = ReadAnalog18ExtendEnt(fileAnalogExtendPath, childAnalogExtendNum);
                    Debug.WriteLine(childAnalogExtendNum + "=" + changeAnalogNum);
                }
                //开关量扩展库
                string childKGLNumStr = ReadIni.GetProfileString(fileAnalogExtendPath, "开关量扩展列信息", "总路数", "-1");
                if (childKGLNumStr == "" || childKGLNumStr == "-1")
                {
                    return isRight;
                }
                //检查是否为数字
                if (Regex.IsMatch(childKGLNumStr, "[0-9]+"))
                {
                    int childDigitNum = int.Parse(childKGLNumStr);
                    int changeDigitNum = ReadKGL18ExtendEnt(fileAnalogExtendPath, childDigitNum);
                    Debug.WriteLine(childDigitNum + "=" + changeDigitNum);
                }

            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message);
            }

            return isRight;
        }

        /// <summary>
        /// 读取生成18版模拟量元素
        /// </summary>
        /// <param name="fileAnalogPath"></param>
        /// <param name="childName"></param>
        /// <returns></returns>
        private int ReadAnalog18Ent(string fileAnalogPath, string childName)
        {
            int changeNum = 0;
            int analogJYNum = 0;
            int analogLLNum = 0;
            int analogNormalNum = 0;
            int beansType = -1;
            //获取总路数字符串
            try
            {
                string childAnalogNumStr = ReadIni.GetProfileString(fileAnalogPath, childName, "总路数", "-1");
                //去除注释
                if (childAnalogNumStr.Contains(";"))
                {
                    int notesLocal = childAnalogNumStr.IndexOf(";");
                    childAnalogNumStr = childAnalogNumStr.Substring(0, notesLocal);
                }
                //判断非null
                if (childAnalogNumStr == "-1")
                {
                    return changeNum;
                }
                //判断为纯数字
                if (Regex.IsMatch(childAnalogNumStr, "[0-9]+"))
                {
                    int childAnalogNum = int.Parse(childAnalogNumStr);
                    for (int j = 0; j < childAnalogNum; j++)
                    {
                        string analogId = (j + 1).ToString();
                        string childAnalogTemp = ReadIni.GetProfileString(fileAnalogPath, childName, analogId, "null");
                        if (childAnalogTemp == "null")
                        {
                            Debug.WriteLine("读取" + childName + "时，未获取到行" + analogId);
                            continue;
                        }
                        //规整数据。，去除空格
                        childAnalogTemp = childAnalogTemp.Replace(" ", "");
                        childAnalogTemp = childAnalogTemp.Replace("\t", "");
                        string[] childAnalogArrayTemp = childAnalogTemp.SplitRemoveEndEmptyEntries(new string[] { "," });
                        if (childAnalogArrayTemp.Length <= 1)
                        {
                            Debug.WriteLine("模拟量行分隔符错误:非英文的逗号");
                            continue;
                        }
                        //数据转储
                        List<string> childAnalogArray = new List<string>();
                        for (int k = 0; k < 17; k++)
                        {
                            if (k >= childAnalogArrayTemp.Length)
                            {
                                childAnalogArray.Add("=-=");
                                continue;
                            }
                            childAnalogArray.Add(childAnalogArrayTemp[k]);
                        }
                        int analogOrderByType = -1;
                        if (childAnalogArray[0] == "=-=")
                        {
                            continue;
                        }
                        //判断为绝缘
                        else if (Convert.ToInt32(childAnalogArray[0], 16) == 59)
                        {
                            analogJYNum++;
                            analogOrderByType = analogJYNum;
                            beansType = 0;
                        }
                        //判断为漏流
                        else if (Convert.ToInt32(childAnalogArray[0], 16) == 60)
                        {
                            analogLLNum++;
                            analogOrderByType = analogLLNum;
                            beansType = 1;
                        }
                        //判断为其他模拟量
                        else
                        {
                            analogNormalNum++;
                            analogOrderByType = analogNormalNum;
                            beansType = 2;
                        }
                        //创建18版模拟量元素
                        AnalogEnt18 analogEnt18Temp = new AnalogEnt18(
                                analogOrderByType,
                                childAnalogArray[0],
                                childAnalogArray[1],
                                int.Parse(childAnalogArray[2]),
                                int.Parse(childAnalogArray[3]),
                                int.Parse(childAnalogArray[4]),

                                float.Parse(childAnalogArray[5]),
                                float.Parse(childAnalogArray[6]),
                                float.Parse(childAnalogArray[7]),
                                float.Parse(childAnalogArray[8]),
                                float.Parse(childAnalogArray[9]),
                                float.Parse(childAnalogArray[10]),

                                int.Parse(childAnalogArray[11]),
                                childAnalogArray[12],

                                childAnalogArray[13],
                                childAnalogArray[14],
                                childAnalogArray[15],
                                childAnalogArray[16]
                        );
                        switch (beansType)
                        {
                            case 0: AnalogJY18EntMap.Add(analogOrderByType, analogEnt18Temp); break;
                            case 1: AnalogLL18EntMap.Add(analogOrderByType, analogEnt18Temp); break;
                            case 2: Analog18EntMap.Add(analogOrderByType, analogEnt18Temp); break;
                            default:
                                Debug.WriteLine("ERROR!"); break;
                        }
                        changeNum++;
                    }
                }
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message);
            }
            return changeNum;
        }

        /// <summary>
        /// 读取生成18版曲线元素
        /// </summary>
        /// <param name="fileAnalogPath"></param>
        /// <param name="childName"></param>
        /// <returns></returns>
        private int ReadCurve18Ent(string fileAnalogPath, string childName)
        {
            int changeNum = 0;
            int curveDCNum = 0;
            int curveOtherNum = 0;
            int beansType = -1;
            //获取总路数字符串
            try
            {
                string childCuveNumStr = ReadIni.GetProfileString(fileAnalogPath, childName, "总路数", "-1");
                //去除注释
                if (childCuveNumStr.Contains(";"))
                {
                    int notesLocal = childCuveNumStr.IndexOf(";");
                    childCuveNumStr = childCuveNumStr.Substring(0, notesLocal);
                }
                //判断非null
                if (childCuveNumStr == "-1")
                {
                    return changeNum;
                }
                //判断为纯数字
                if (Regex.IsMatch(childCuveNumStr, "[0-9]+"))
                {
                    int childCurveNum = int.Parse(childCuveNumStr);
                    for (int j = 0; j < childCurveNum; j++)
                    {
                        string analogId = (j + 1).ToString();
                        string childCurveTemp = ReadIni.GetProfileString(fileAnalogPath, childName, analogId, "null");
                        if (childCurveTemp == "null")
                        {
                            Debug.WriteLine("读取" + childName + "时，未获取到行" + analogId);
                            continue;
                        }
                        //规整数据。，去除空格
                        childCurveTemp = childCurveTemp.Replace(" ", "");
                        childCurveTemp = childCurveTemp.Replace("\t", "");
                        string[] childCurveArrayTemp = childCurveTemp.SplitRemoveEndEmptyEntries(new string[] { "," });
                        if (childCurveArrayTemp.Length <= 1)
                        {
                            Debug.WriteLine("曲线行分隔符错误:非英文的逗号");
                            continue;
                        }
                        //数据转储
                        List<string> childCurveArray = new List<string>();
                        for (int k = 0; k < 17; k++)
                        {
                            if (k >= childCurveArrayTemp.Length)
                            {
                                childCurveArray.Add("=-=");
                                continue;
                            }
                            childCurveArray.Add(childCurveArrayTemp[k]);
                        }
                        int analogOrderByType = -1;
                        if (childCurveArray[0] == "=-=")
                        {
                            continue;
                        }
                        //判断为道岔曲线量
                        else if (Convert.ToInt32(childCurveArray[0], 16) == 0)
                        {
                            curveDCNum++;
                            analogOrderByType = curveDCNum;
                            beansType = 1;
                        }
                        //判断为其他曲线量
                        else
                        {
                            curveOtherNum++;
                            analogOrderByType = curveOtherNum;
                            beansType = 2;
                        }
                        //创建18版模拟量元素
                        AnalogEnt18 analogEnt18Temp = new AnalogEnt18(
                                analogOrderByType,
                                childCurveArray[0],
                                childCurveArray[1],
                                int.Parse(childCurveArray[2]),
                                int.Parse(childCurveArray[3]),
                                int.Parse(childCurveArray[4]),

                                float.Parse(childCurveArray[5]),
                                float.Parse(childCurveArray[6]),
                                float.Parse(childCurveArray[7]),
                                float.Parse(childCurveArray[8]),
                                float.Parse(childCurveArray[9]),
                                float.Parse(childCurveArray[10]),

                                int.Parse(childCurveArray[11]),
                                childCurveArray[12],

                                childCurveArray[13],
                                childCurveArray[14],
                                childCurveArray[15],
                                childCurveArray[16]
                        );

                        switch (beansType)
                        {
                            case 1: CurveDC18EntMap.Add(analogOrderByType, analogEnt18Temp); break;
                            case 2: CurveOther18EntMap.Add(analogOrderByType, analogEnt18Temp); break;
                            default:
                                Debug.WriteLine("ERROR!"); break;
                        }
                        changeNum++;
                    }
                }
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message);
            }
            return changeNum;
        }

        /// <summary>
        /// 读取生成18版模拟量扩展元素
        /// </summary>
        /// <param name="fileAnalogExtendPath"></param>
        /// <param name="childNum"></param>
        /// <returns></returns>
        private int ReadAnalog18ExtendEnt(string fileAnalogExtendPath, int childNum)
        {
            int changeNum = 0;
            string childName = "";
            int childId = 0;
            int beansType = -1;
            //获取总路数字符串
            try
            {
                Dictionary<string, List<string>> keyValuePairs = ReadIni.FastReadTDSectionAllLine(fileAnalogExtendPath, childNum, "模拟量", "扩展列", "-1");
                if (keyValuePairs == null || keyValuePairs.Count <= 0)
                {
                    return changeNum; 
                }
                
                for (int i = 0; i < childNum; i++)
                {
                    int analogExtendId = 0;
                    string dataType = "";
                    string dataName = "";
                    int analogType = 0;
                    int analogTypeOrder = 0;
                    int analogOrder = 0;

                    Dictionary<string, string> analogProperty = new Dictionary<string, string>();

                    List<string> childAnalogExtendList = new List<string>();
                    childId = i + 1;
                    childName = "[模拟量" + childId + "扩展列]";

                    if (keyValuePairs.ContainsKey(childName))
                    {
                        childAnalogExtendList = keyValuePairs[childName];
                    }
                    else
                    {
                        continue;
                    }
                    //childAnalogExtendList = ReadIni.ReadSectionAllLine(fileAnalogExtendPath, childName, "-1");

                    for (int j = 0; j < childAnalogExtendList.Count; j++)
                    {
                        string childAnalogExtendTemp = childAnalogExtendList[j];
                        //规整数据。，去除空格
                        childAnalogExtendTemp = childAnalogExtendTemp.Replace(" ", "");
                        childAnalogExtendTemp = childAnalogExtendTemp.Replace("\t", "");
                        //去除注释
                        if (childAnalogExtendTemp.Contains(";"))
                        {
                            int notesLocal = childAnalogExtendTemp.IndexOf(";");
                            childAnalogExtendTemp = childAnalogExtendTemp.Substring(0, notesLocal);
                        }
                        //判断非null
                        if (childAnalogExtendTemp.Length == 0)
                        {
                            continue;
                        }
                        string[] strAnalogExtends = childAnalogExtendTemp.SplitRemoveEndEmptyEntries(new string[] { "=" });
                        if (strAnalogExtends.Length == 0)
                        {
                            continue;
                        }
                        else if (strAnalogExtends.Length == 1)
                        {
                            if (analogExtendKey.Contains(strAnalogExtends[0]))
                            {
                                analogProperty.Add(strAnalogExtends[0], "");
                            }
                        }
                        else if (strAnalogExtends.Length >= 2)
                        {
                            if (strAnalogExtends[0] == "扩展列序号")
                            {
                                analogExtendId = int.Parse(strAnalogExtends[1]);
                            }
                            else if (strAnalogExtends[0] == "数据类型")
                            {
                                dataType = strAnalogExtends[1];
                                if (dataType == "记录曲线")
                                {
                                    beansType = 2;
                                }
                                else if (dataType == "模拟量")
                                {
                                    beansType = 1;
                                }
                            }
                            else if (strAnalogExtends[0] == "名称")
                            {
                                dataName = strAnalogExtends[1];
                            }
                            else if (strAnalogExtends[0] == "模拟量类型")
                            {
                                analogType = int.Parse(strAnalogExtends[1]);
                            }
                            else if (strAnalogExtends[0] == "模拟量序号")
                            {
                                analogTypeOrder = int.Parse(strAnalogExtends[1]);
                            }
                            else if (strAnalogExtends[0] == "analog大排队序号")
                            {
                                analogOrder = int.Parse(strAnalogExtends[1]);
                            }
                            else if (analogExtendKey.Contains(strAnalogExtends[0]))
                            {
                                analogProperty.Add(strAnalogExtends[0], strAnalogExtends[1]);
                            }
                        }
                        else
                        {
                            Debug.WriteLine("ERROR!");
                            continue;
                        }
                    }
                    //创建18版模拟量扩展元素
                    AnalogExtend18 analogExtend18Temp = new AnalogExtend18(
                            analogExtendId,
                            dataType,
                            dataName,
                            analogType,
                            analogTypeOrder,
                            analogOrder,
                            analogProperty
                    );
                    //System.out.println(analogExtend18Temp);
                    if (beansType == 1)
                    {
                        AnalogExtend18EntMap.Add(analogOrder, analogExtend18Temp);
                    }
                    else if (beansType == 2)
                    {
                        CurveExtend18EntMap.Add(analogOrder, analogExtend18Temp);
                    }
                    else
                    {
                        Debug.WriteLine("ERROR!未知的模拟量类型");
                        continue;
                    }
                    changeNum++;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return changeNum;
        }

        /// <summary>
        /// 读取生成18版开关量扩展元素
        /// </summary>
        /// <param name="fileAnalogExtendPath"></param>
        /// <param name="childNum"></param>
        /// <returns></returns>
        private int ReadKGL18ExtendEnt(string fileAnalogExtendPath, int childNum)
        {
            int changeNum = 0;
            string childName = "";
            int childId = 0;
            //获取总路数字符串
            try
            {
                Dictionary<string, List<string>> keyValuePairs = ReadIni.FastReadTDSectionAllLine(fileAnalogExtendPath, childNum, "开关量", "扩展列", "-1");
                if (keyValuePairs == null || keyValuePairs.Count <= 0)
                {
                    return changeNum;
                }

                for (int i = 0; i < childNum; i++)
                {
                    //扩展列序号
                    int kglExtendId = 0;
                    //数据类型=开关量
                    string dataType = "";
                    //名称=SYSA-ONLINE-MR
                    string dataName = "";
                    //模拟量类型=248
                    int digitType = 0;
                    //null
                    int digitTypeOrder = -1;
                    //开关量序号=0
                    int digitOrder = 0;

                    Dictionary<string, string> digitProperty = new Dictionary<string, string>();

                    List<string> childDigitExtendList = new List<string>();
                    childId = i + 1;
                    childName = "[开关量" + childId + "扩展列]";
                    //获取对象的额外键值对
                    if (keyValuePairs.ContainsKey(childName))
                    {
                        childDigitExtendList = keyValuePairs[childName];
                    }
                    else
                    {
                        continue;
                    }
                    //childDigitExtendList = ReadIni.ReadSectionAllLine(fileAnalogExtendPath, childName, "-1");

                    for (int j = 0; j < childDigitExtendList.Count; j++)
                    {
                        string childDigitExtendTemp = childDigitExtendList[j];
                        //规整数据。，去除空格
                        childDigitExtendTemp = childDigitExtendTemp.Replace(" ", "");
                        childDigitExtendTemp = childDigitExtendTemp.Replace("\t", "");
                        //去除注释
                        if (childDigitExtendTemp.Contains(";"))
                        {
                            int notesLocal = childDigitExtendTemp.IndexOf(";");
                            childDigitExtendTemp = childDigitExtendTemp.Substring(0, notesLocal);
                        }
                        //判断非null
                        if (childDigitExtendTemp.Length == 0)
                        {
                            continue;
                        }
                        string[] strDigitExtends = childDigitExtendTemp.SplitRemoveEndEmptyEntries(new string[] { "=" });
                        if (strDigitExtends.Length == 0)
                        {
                            continue;
                        }
                        else if (strDigitExtends.Length == 1)
                        {
                            if (analogExtendKey.Contains(strDigitExtends[0]))
                            {
                                digitProperty.Add(strDigitExtends[0], "");
                            }
                        }
                        else if (strDigitExtends.Length >= 2)
                        {
                            if (strDigitExtends[0] == "扩展列序号")
                            {
                                kglExtendId = int.Parse(strDigitExtends[1]);
                            }
                            else if (strDigitExtends[0] == "数据类型")
                            {
                                dataType = strDigitExtends[1];
                            }
                            else if (strDigitExtends[0] == "名称")
                            {
                                dataName = strDigitExtends[1];
                            }
                            else if (strDigitExtends[0] == "模拟量类型")
                            {
                                digitType = int.Parse(strDigitExtends[1]);
                            }
                            else if (strDigitExtends[0] == "开关量序号")
                            {
                                digitOrder = int.Parse(strDigitExtends[1]);
                            }
                            else if (analogExtendKey.Contains(strDigitExtends[0]))
                            {
                                digitProperty.Add(strDigitExtends[0], strDigitExtends[1]);
                            }
                        }
                        else
                        {
                            Debug.WriteLine("ERROR!");
                            continue;
                        }
                    }
                    //创建18版开关量扩展元素
                    AnalogExtend18 digitExtend18Temp = new AnalogExtend18(
                            kglExtendId,
                            dataType,
                            dataName,
                            digitType,
                            digitTypeOrder,
                            digitOrder,
                            digitProperty
                    );
                    DigitExtend18EntMap.Add(digitOrder, digitExtend18Temp);
                    changeNum++;
                }
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message);
            }
            return changeNum;
        }

    }
}
